//
//  ViewController.m
//  BZGCode
//
//  Created by coderz on 2019/11/21.
//  Copyright © 2019 coderz. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) BZGBaseTableView *mainTableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor orangeColor];
    
    [self.view addSubview:self.mainTableView];
    
    self.title = @"demo";
    
    self.dataSource = [NSMutableArray arrayWithArray:[BZGBaseModel returnBZGBaseModel]];
}

#pragma maek -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    
    BZGBaseModel *model = self.dataSource[indexPath.section];
    cell.textLabel.text = model.title;
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BZGBaseModel *model = self.dataSource[indexPath.section];
    
    if (indexPath.section == 0) {
        [self weixinPay];
    } else if (indexPath.section == 1) {
        BZGMixedDevelopmentController *vc = [[BZGMixedDevelopmentController alloc] init];
        
        vc.title = model.title;
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if (indexPath.section == 2) {
        BZGUISegmentedControlController *vc = [BZGUISegmentedControlController new];
        vc.title = model.title;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.section == 3) {
        BZGUnderObjectController *vc = [BZGUnderObjectController new];
        vc.title = model.title;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else {
        
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}

-(BZGBaseTableView *)mainTableView {
    if (_mainTableView == nil) {
        _mainTableView = [[BZGBaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        
        [_mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    }
    return _mainTableView;
}

-(NSMutableArray *)dataSource {
    if (_dataSource == nil) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    [self weixinPay];
//}

- (void)weixinPay { //微信支付
    [WXApiRequestHandler jumpToBizPay];
}

- (void)precision {//精度问题
    NSString *str = @"68.12310";
    
    NSLog(@"%@",[NSDecimalNumber decimalNumberWithString:str]);
    NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:str];
    NSLog(@"%@",[num stringValue]);
}

- (NSString *)strConvertDateWithStr:(NSString *)str{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];//格式化
    NSDateFormatter * dfTwo = [[NSDateFormatter alloc] init];
    if (str.length > 8) {
        [df setDateFormat:@"yyyyMMddHHmmss"];
        [dfTwo setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    }else{
        [df setDateFormat:@"yyyyMMdd"];
        [dfTwo setDateFormat:@"yyyy-MM-dd"];
    }
    [df setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"] ];
    NSDate *date;
    date = [df dateFromString:str];
    NSString * dateStr = [dfTwo stringFromDate:date];
    return dateStr;
}


@end
